<template>
	<view class="tools" :class="[isLike?'isLike':'']">
		<i class="iconfont icon-dianzan" @click="like"></i>
		<text class="num" v-if="likeCount>0">{{likeCount}}</text>
	</view>
</template>
<style scoped lang="scss">
	.tools {
		display: flex;
		align-items: baseline;
		margin: 10px 0 20px 0;

		&.isLike {
			color: $base-color !important;

			.iconfont,.num {
				color: $base-color !important;
			}
		}

		.num {
			font-size: 32rpx;
			color: #999;
			margin-left: 5rpx;
		}

		.iconfont {
			font-size: 46rpx;
			color: #999;
			margin-left: 26rpx;


		}
	}
</style>
<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	import {
		doLike
	} from '@/api/api.js';
	export default {
		name: 'Like',
		props: ['wid', 'reply_id', 'count'],
		data() {
			return {
				isLike: false,
				likeCount: '',
			}
		},
		mounted(options) {
			console.log(this.reply_id)
			this.likeCount = this.count || 0
		},
		computed: {
			...mapState(['hasLogin', 'userInfo']),
		},
		methods: {
			like() {
				let _this = this
				if (!this.hasLogin) {
					uni.$u.toast('请登录');
				} else {
					doLike({
						reply_id: _this.reply_id,
						wid: _this.wid
					}).then(r => {
						if (r.data.code == 200) {
							_this.likeCount = r.data.data
							_this.isLike = true
						} else if (r.data.code == 500) {
							_this.isLike = true
						}
					})
				}
			},
		}
	}
</script>